from syslogd.configuration.ConfObject import ConfObject
from syslogd.configuration.Rule import Rule



class ConfParser(object):

    @staticmethod
    def createConfObjects(lst):
        
        confObjects = []
        for el in lst:
            commented = False
            if el[0] == '#':
                commented = True
                el = el[1:]
            tab = el.split()
            spec = None
            path = None
            char = tab[1][0]
            if char == '-' or char == '|' or char == '@':
                spec = char
                path = tab[1][1:]     
            else:
                path = tab[1] 
              
            rules = []   
            rls = tab[0].split(';')
            for rl in rls:
                rr = rl.split('.')
                functions = rr[0].split(',')
                modifier = None
                if rr[1][0] == '=' or rr[1][0] == '!': 
                    modifier = rr[1][0]
                    rr[1] = rr[1][1:]
                rules.append(Rule(functions,modifier,rr[1]))
            confObjects.append(ConfObject(rules,spec,path,commented))
        return confObjects